
//gcc -o ./bin/crypt unistd/crypt.c -lcrypt
#include <stdio.h>
#include <stdlib.h>

#define _XOPEN_SOURCE
#include <unistd.h>
#include <crypt.h>
#include <shadow.h>

int main(int argc, char *argv[])
{
    char *input_pass;
    struct spwd *shadowline;
    char *crypted_pass;

    if (argc < 2)
    {
        fprintf(stderr, "Usage ...\n");
        exit(1);
    }

    input_pass = getpass("PassWord:");
    shadowline = getspnam(argv[1]);
    crypted_pass = crypt(input_pass, shadowline->sp_pwdp);

    if (strcmp(crypted_pass, shadowline->sp_pwdp) == 0)
        puts("OK!");
    else
        puts("Faile!");
    exit(0);
}